<!--
 * @Author: your name
 * @Date: 2022-04-01 17:10:07
 * @LastEditTime: 2022-04-01 17:11:35
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\深拷贝实现方式ES5220401.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>深拷贝ES5</title>
</head>

<body>
  <script>
    //深拷贝ES5方式
    function deepClone(origin, target) {
      var tar = target || {};
      var toStr = Object.prototype.toString;
      var arrType = '[object Array]';

      for (var k in origin) {
        if (origin.hasOwnProperty(k)) {
          if (typeof origin[k] === 'object' && origin[k] !== null) {
            tar[k] = toStr.call(origin[k]) === arrType ? [] : {};
            deepClone(origin[k], tar[k]);
          } else {
            tar[k] = origin[k];
          }
        }
      }

      return tar;
    }
  </script>
</body>

</html>